package com.sq.partner.manager.service.impl;
import com.sq.partner.manager.dao.ZfbInfoDao;
import com.sq.partner.manager.service.ZfbInfoService;
import com.sq.partner.manager.util.Page;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service
public class ZfbInfoServiceImpl implements ZfbInfoService {
    @Resource
    ZfbInfoDao zfbInfoDao;

    @Override
    public Page queryZfbBillInfoPage(Page page) throws Exception {
        return zfbInfoDao.queryZfbBillInfoPage(page);
    }

    @Override
    public HSSFWorkbook generateHssWorkBook(String sheetName, int columnNumber, int[] columnWidth, String[] columnName, String[][] zfbInfos) throws Exception {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet(sheetName);
        for (int i = 0; i < columnNumber; i++) {
            sheet.setColumnWidth(i, columnWidth[i] * 256);
        }
        HSSFRow headerRow = sheet.createRow(0);
        // 第"0"行行高设置为40
        headerRow.setHeightInPoints(40);
        // 表头单元格样式
        HSSFCellStyle headerStyle = wb.createCellStyle();
        // 设置自动换行
        headerStyle.setWrapText(true);
        // 居中样式
        headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        headerStyle.setBottomBorderColor(HSSFColor.BLACK.index);
        headerStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        headerStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        headerStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        headerStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        // 设置表头字体样式
        HSSFFont headerFont = wb.createFont();
        headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerFont.setFontName("宋体");
        // 设置字体大小
        headerFont.setFontHeightInPoints((short) 10);
        headerStyle.setFont(headerFont);

        HSSFCell cell = null;
        for (int i = 0; i < columnNumber; i++) {
            cell = headerRow.createCell(i);
            cell.setCellValue(columnName[i]);
            cell.setCellStyle(headerStyle);
        }
        HSSFRow row = null;
        // 数据的样式
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        style.setBottomBorderColor(HSSFColor.BLACK.index);
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
        style.setFont(font);
        for (int i = 0; i < zfbInfos.length; i++) {
            row = sheet.createRow(i + 1);
            for (int j = 0; j < columnNumber; j++) {
                cell = row.createCell(j);
                row.setHeightInPoints(16);
                cell.setCellValue(zfbInfos[i][j]);
                cell.setCellStyle(style);
            }
        }
        return wb;
    }

    @Override
    public List<Map<String, Object>> queryZfbBillInfoList(Map<String, Object> map) throws Exception {
        return zfbInfoDao.queryZfbBillInfoList(map);
    }

    @Override
    public Page queryZfbRefundInfoPage(Page page) throws Exception {
        return zfbInfoDao.queryZfbRefundInfoPage(page);
    }

    @Override
    public List<Map<String, Object>> queryZfbRefundInfoList(Map<String, Object> map) throws Exception {
        return zfbInfoDao.queryZfbRefundInfoList(map);
    }
}
